package com.ziyun.erp.web.modules.goodsImage.controller;

import com.ziyun.erp.common.utils.UserUtils;
import com.ziyun.erp.modules.goodsImage.entity.GoodsImageEntity;
import com.ziyun.erp.modules.goodsImage.service.GoodsImageService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 图片表
 *
 * @author
 * @email
 * @date 2018-08-29 08:42:27
 */
@RestController
@RequestMapping("goodsImage/goodsimage")
public class GoodsImageController {
    @Autowired
    private GoodsImageService goodsImageService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("goodsImage:goodsimage:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = goodsImageService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
        GoodsImageEntity goodsImage = goodsImageService.selectById(id);

        return R.ok().put("goodsImage", goodsImage);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody GoodsImageEntity goodsImage){

        goodsImageService.insert(goodsImage);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody GoodsImageEntity goodsImage){
        ValidatorUtils.validateEntity(goodsImage);
        goodsImageService.updateAllColumnById(goodsImage);//全部更新

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
        goodsImageService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 保存
     */
    @RequestMapping("/saveImage")
    public R saveImage(@RequestBody GoodsImageEntity goodsImage){
        goodsImage.setCreateName(UserUtils.getCurentUser().getUsername());
        goodsImageService.saveImage(goodsImage);
        return R.ok().put("id",goodsImage.getId());
    }

}
